package com.ruoyi.job.util;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.client.Stub;
import org.apache.axis.description.OperationDesc;
import org.apache.axis.description.ParameterDesc;
import org.springframework.stereotype.Component;

import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Map;

/**
 * 手机短信接入
 * @author Administrator
 *
 */
@Component
public class ShortMessageServiceSupport extends Stub{

	/**
	 * 短信接入服务地址
	 */
//	@Value("${short.message.service.url}")
//	private String shortMessageServiceUrl;
//	@Value("${short.message.service.modeNo}")
//	private String modeNo;

	private  String shortMessageServiceUrl = "http://32.172.32.186:10000/DXPTSvc/SMSService.svc?wsdl";
	private  String modeNo = "082040300005";
	
	/***
	 * 发送短信
	 * @param cellphone 手机号码
	 * @param content 短信内容
	 * @return
	 */
	public  Map<String, Object> sendShortMessage(String cellphone, String content){

		
		Map<String, Object> map = new HashMap<>();
		map.put("success", true);

        try {
    		OperationDesc oper = new OperationDesc();
            oper.setName("Send067021000002");
            ParameterDesc param = new ParameterDesc(new javax.xml.namespace.QName("http://tempuri.org/", "ModeNo"), 
            		org.apache.axis.description.ParameterDesc.IN, 
            		new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), 
            		String.class, false, false);
            param.setOmittable(false);
            param.setNillable(true);
            oper.addParameter(param);
            
            param = new ParameterDesc(new javax.xml.namespace.QName("http://tempuri.org/", "cellPhone"), 
            		org.apache.axis.description.ParameterDesc.IN, 
            		new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), 
            		String.class, false, false);
            param.setOmittable(false);
            param.setNillable(true);
            oper.addParameter(param);
            
            param = new ParameterDesc(new javax.xml.namespace.QName("http://tempuri.org/", "content"), 
            		org.apache.axis.description.ParameterDesc.IN, 
            		new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), 
            		String.class, false, false);
            param.setOmittable(false);
            param.setNillable(true);
            oper.addParameter(param);
            
            oper.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);
            oper.setStyle(org.apache.axis.constants.Style.WRAPPED);
            oper.setUse(org.apache.axis.constants.Use.LITERAL);
    		
    		Service service = new Service();
    		Call _call = new Call(service);
    		_call.setTargetEndpointAddress(shortMessageServiceUrl);  
            _call.setOperation(oper);
            _call.setUseSOAPAction(true);
            _call.setSOAPActionURI("http://tempuri.org/ISMSService/Send067021000002");
            _call.setEncodingStyle(null);
            _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
            _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
            _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
            _call.setOperationName(new javax.xml.namespace.QName("http://tempuri.org/", "Send067021000002"));
            
            setRequestHeaders(_call);
            setAttachments(_call);
            
            try {
    			_call.invoke(new Object[] {modeNo, cellphone, content});
    		} catch (RemoteException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
            
		} catch (Exception e) {
			map.put("success", false);
			map.put("data", e.getMessage());
		}
        return map;
	}
}
